<?php
if (!$_POST){
    include "Views/back_login_View.html";
}else{
    $link=require_once 'sqlLink.php';
    $name=isset($_POST['userName'])? $_POST['userName']:'';
    $getpwd=isset($_POST['userPwd'])? $_POST['userPwd']:'';
    if (!$name || !$getpwd) {
        die('用户名或密码不能为空');
    }
    $sql="select * from user_info where userName='$name'";
    $res=mysqli_query($link,$sql);
    if (!$res){
        die("用户名有误！");
    }
    $userData=mysqli_fetch_assoc($res);
    if (!$userData) {
        die('未找到该用户！');
    }
    $getpwd=isset($_POST['userPwd'])? $_POST['userPwd']:'';
    $pwd= md5(md5($getpwd).$userData['salt']);
    if ($pwd != $userData['userPwd']) {
        echo $pwd."<br>".$userData['userPwd'];
        die('用户名或密码错误');
    }
    //启动会话
    session_start();
    //存储用户信息
    $_SESSION['user'] = [
        'id' => $userData['id'],
        'name' => $userData['userName']
    ];
    //跳转初始页面
    header('Location:back_product_list.php');
    die;
}